package com.xy.test.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/provider/dept")
@RefreshScope //实现配置自动更新
public class DeptController {

    @Value("${default.dt}")
    private String dt;

    @GetMapping("/dt")
    public String dt() {
        return dt;
    }


    @GetMapping("/get/{id}")
    // 当服务出现异常后调用指定的处理方法
    public String getDept(@PathVariable(value = "id") Integer id) {
        if (id == 0) {
            // 模拟抛出异常的情况
            throw new RuntimeException("该ID： " + id + " 不存在");
        }
        return "dept:" + id;
    }

    @GetMapping("/list")
    public List<String> getDeptList() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        return list;
    }
}
